package com.xxx.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.function.Consumer;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/26 15:42
 * @Copyright 博为峰
 */
public class StreamDemo {
    /*
        JDK版本变化
        1.语法
        2.API
        3.性能（JVM）
     */

    /*
       Stream操作数据三个步骤
       1.创建Stream
         数据源(数组，集合)
       2.中间操作
       3.终止操作
     */

    public static void main(String[] args) {
//        m1();
        ArrayList<Student> arrayList = new ArrayList<>();
        arrayList.add(new Student(101, "张三", 20, 96));
        arrayList.add(new Student(102, "李四", 10, 80));
        arrayList.add(new Student(103, "王五", 30, 66));
        arrayList.add(new Student(104, "赵六", 22, 70));
        arrayList.add(new Student(105, "张三峰", 16, 82));
        arrayList.add(new Student(106, "李思思", 28, 76));
        arrayList.add(new Student(107, "赵四", 35, 67));
        arrayList.add(new Student(108, "郭德纲", 32, 95));
        arrayList.add(new Student(109, "岳云鹏", 9, 92));
        arrayList.add(new Student(110, "张云雷", 36, 87));

//        for (Student student : arrayList) {
//
//        }

        Stream<Student> stream = arrayList.stream();
//        stream.forEach(new Consumer<ArrayList<Student>>() {
//            @Override
//            public void accept(ArrayList<Student> students) {
//
//            }
//        });
//        stream.forEach(student -> {
//            System.out.println(student.getName());
//        });

//        stream.forEach(System.out::println);

        stream.filter(stu -> stu.getName().startsWith("张")).forEach(System.out::println);

        //limit sorted distinct() count()  skip(long n)

    }

    private static void m1() {
        //1.从集合中获取Stream流对象
        ArrayList<String> strings = new ArrayList<>();
        Stream<String> stream = strings.stream();//顺序流
        Stream<String> stringStream = strings.parallelStream();//并行流

        //2.从数组中获取Stream流对象
        int[] ints = {1, 2, 3,};
        IntStream intStream = Arrays.stream(ints);

        //3.通过Stream的of()方法
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5, 6);
        Stream<HashSet<String>> hashSetStream = Stream.of(new HashSet<String>());
    }
}
